package ui.components;

import ui.components.JJTable;

import javax.swing.table.DefaultTableCellRenderer;
import java.text.DecimalFormat;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.LineBorder;


public class JJColoredTableCellRenderer
        extends DefaultTableCellRenderer{

    public JJColoredTableCellRenderer() {
    }

    public Component getTableCellRendererComponent(JTable table, Object value,
                                                   boolean isSelected, boolean hasFocus, int row,int column) {
        Component renderer = super.getTableCellRendererComponent(table, value, isSelected,
                hasFocus, row, column);

        if (value instanceof Boolean) {
            ((JLabel)renderer).setText("");
            if (value.equals(true))
                ((JLabel)renderer).setIcon(new ImageIcon("./icons/accept.png"));
            else
                ((JLabel)renderer).setIcon(new ImageIcon("./icons/cancel.png"));
        } else
            ((JLabel)renderer).setIcon(null);    

//                renderer.setBackground(new Color(0xff, 0xcc, 0x00));
        if (table instanceof JJTable) {
            Color color = ((JJTable) table).getRowColor(row);
            if (color == null) {
                if (isSelected)
                    ((JLabel)renderer).setBackground(new Color(0xff, 0xcc, 0x00));
                else {
                    if (row==0)
//                        renderer.setBackground(new Color(240, 250, 220));
                        renderer.setBackground(new Color(0xCB, 0xDC, 0xED));
                    else if (1 == row % 2)
//                        renderer.setBackground(new Color(0xC8, 0xEC, 0x7D));
                        renderer.setBackground(new Color(0xA0, 0xBF, 0xDE));
                    else
                        renderer.setBackground(new Color(0xCB, 0xDC, 0xED));
                }
            } else {
                if (isSelected)
                    ((JLabel)renderer).setBorder(new LineBorder(new Color(0xff, 0xcc, 0x00), 2));
                renderer.setBackground(color);
            }

        }
        return renderer;
    }
}